package com.heima.wemedia.controller;

import com.heima.model.channel.dtos.ChannelDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {
    @Autowired
    private WmChannelService wmChannelService;

    /**
     * 查询所有频道
     */
    @GetMapping("/channels")
    public ResponseResult<List<WmChannel>> findAll(){
        return wmChannelService.findAll();
    }

    /**
     * 删除频道
     */
    @GetMapping("/del/{id}")
    public ResponseResult<String> delete(@PathVariable Integer id){
        return wmChannelService.delChannel(id);
    }

    /**
     * 频道搜索
     */
    @PostMapping("/list")
    public ResponseResult<List<WmChannel>> list(@RequestBody ChannelDto channelDto){
        return wmChannelService.likeQuery(channelDto);
    }

    /**
     * 修改频道
     */
    @PostMapping("/update")
    public ResponseResult<String> update(@RequestBody WmChannel wmChannel){
        return wmChannelService.modifyChannel(wmChannel);
    }

    /**
     * 新增频道
     */
    @PostMapping("/save")
    public ResponseResult<String> save(@RequestBody WmChannel wmChannel){
        return wmChannelService.addChannel(wmChannel);
    }

}
